package cn.zn.controller.system;

import cn.zn.base.annotation.Log;
import cn.zn.base.bean.dto.ResultData;
import cn.zn.base.common.enums.BusinessType;
import cn.zn.base.common.utils.ResultUtil;
import cn.zn.log.entity.SysOperateLog;
import cn.zn.log.service.SysOperateLogService;
import cn.zn.log.vo.SysOperateLogPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 操作日志记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/log/operate")
public class SysOperateLogController {

    @Autowired
    private SysOperateLogService operateLogService;

    @PreAuthorize("@ss.hasPermi('log:operate:list')")
    @GetMapping("/list")
    public ResultData list(SysOperateLogPageVo vo) {
        Object result = operateLogService.selectOperateLogList(vo);
        return ResultUtil.success(result);
    }

    @PreAuthorize("@ss.hasPermi('log:operate:info')")
    @GetMapping("/{operateId}")
    public ResultData getInfo(@PathVariable String operateId) {
        SysOperateLog logs = operateLogService.getById(operateId);
        return ResultUtil.success(logs);
    }

    @PreAuthorize("@ss.hasPermi('log:operate:remove')")
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{operateIds}")
    public ResultData remove(@PathVariable String[] operateIds) {
        operateLogService.deleteOperateLogByIds(operateIds);
        return ResultUtil.success();
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('log:operate:remove')")
    @DeleteMapping("/clean")
    public ResultData clean() {
        operateLogService.cleanOperateLog();
        return ResultUtil.success();
    }
}
